package com.auto.code.core.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public enum DataDictionaryEnum {
	GET_SET_FIELD("${get_set_field}", "显示表对应的所有字段"),
	GET_SET_METHOD("${get_set_method}", "字段对应的get set 方法"),
	TABLE_NAME("${table_name}", "表名称"),
	TABLE_CLASS_NAME("${table_class_name}", "表名对应类名"),
	TABLE_OBJ_NAME("${table_obj_name}", "表名对应对象名（首字母小写）"), 
	PACKAGE("${package}", "包路径"),
	TABLE_COMMENT("${table_comment}", "表备注"),

	SQL_MAP_COLUMN("${sql_map_column}", "数据库表返回map"),
	SQL_COLUMN("${sql_column}", "表字段 , 分隔"),
	SQL_UPDATE_FILED("${sql_update_filed}", "更新字段"),
	SQL_COLUMN_ATTR("${sql_column_attr}", "表字段对应java属性 , 分隔"),
	SQL_CONDITION("${condition_sql}", "查询字段"),

	PROJECT_NAME("${project_name}", "项目名称"),
	PROJECT_URLS("${project_urls}", "项目访问路径"),
	;

	private final String value;
	private final String desc;

	private DataDictionaryEnum(String value, String desc) {
		this.value = value;
		this.desc = desc;
	}

	public String getValue() {
		return value;
	}

	public String getDesc() {
		return desc;
	}

	public static DataDictionaryEnum getEnum(String value) {
		DataDictionaryEnum resultEnum = null;
		DataDictionaryEnum[] enumAry = DataDictionaryEnum.values();

		for (int i = 0; i < enumAry.length; i++) {
			if (enumAry[i].getValue().equals(value)) {
				resultEnum = enumAry[i];
				break;
			}
		}

		return resultEnum;
	}

	public static Map<String, Map<String, Object>> toMap() {
		DataDictionaryEnum[] ary = DataDictionaryEnum.values();
		Map<String, Map<String, Object>> enumMap = new HashMap<String, Map<String, Object>>();

		for (int num = 0; num < ary.length; num++) {
			Map<String, Object> map = new HashMap<String, Object>();
			String key = String.valueOf(getEnum(ary[num].getValue()));
			map.put("desc", ary[num].getDesc());
			map.put("value", ary[num].getValue());

			enumMap.put(key, map);
		}

		return enumMap;
	}

	public static List<Map<String, Object>> toList() {
		DataDictionaryEnum[] ary = DataDictionaryEnum.values();
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		for (int i = 0; i < ary.length; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("desc", ary[i].getDesc());
			map.put("value", ary[i].getValue());

			list.add(map);
		}

		return list;
	}

	public static DataDictionaryEnum getValueByName(String name) {
		DataDictionaryEnum roleEnum = null;
		DataDictionaryEnum[] enumAry = DataDictionaryEnum.values();

		for (int i = 0; i < enumAry.length; i++) {
			if (enumAry[i].getDesc().equals(name)) {
				roleEnum = enumAry[i];
				break;
			}
		}
		return roleEnum;
	}
}
